<template>
	<view class="cu-custom" :class="isFixed?'dir-fixed':''" :style="[{height:CustomBar + 'px'}]">
		<view class="cu-bar" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColor,isFixed?'fixed':'']" @close="close">
			<view class="action" @tap="customBack?'':$tools.back()" v-if="isBack">
				<text class="cuIcon-back" :style="{color: color}" v-if="!customBack"></text>
				<slot name="backText"></slot>
			</view>
			<view class="content" :style="[{top:StatusBar + 'px'}]">
				<slot name="content"></slot>
			</view>
			<slot name="right"></slot>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var scrollColor = this.scrollColor;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				if (this.scrollColor) {
					style += `background-color: ${scrollColor};`;
				}
				return style
			}
		},
		props: {
			color: {
				type: String,
				default: ''
			},
			bgColor: {
				type: String,
				default: ''
			},
			scrollColor: {
				type: String,
				default: ''
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			isFixed: {
				type: Boolean,
				default: false
			},
			customBack: {
				type: Boolean,
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			}
		}
	}
</script>

<style>
	.dir-fixed{
		position: fixed;
		z-index: 9999;
		top: 0;
	}
	
	.action {
		padding-right: 20rpx;
	}
	
	.cu-bar .content {
		font-size: 32rpx;
		font-weight: 700;
	}
	
	.cu-bar .action>uni-text[class*="cuIcon-"], .cu-bar .action>uni-view[class*="cuIcon-"] {
		font-size: 32rpx;
	}
</style>
